<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('编辑订单')"/>
</head>
<body>
<form class="layui-form" th:object="${bOrderDispatch}">
    <div class="mainBox">
        <div class="main-container">
            <input name="id" th:field="*{id}" type="hidden">


            <div class="layui-form-item">
                <label class="layui-form-label">客户昵称：</label>
                <div class="layui-input-block">
                    <input type="text" name="clientName" th:field="*{clientName}"
                           placeholder="请输入客户昵称" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系方式：</label>
                <div class="layui-input-block">
                    <input type="text" name="clientContact" th:field="*{clientContact}"
                           placeholder="请输入客户联系方式" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">三方订单：</label>
                <div class="layui-input-block">
                    <input type="text" name="thirdOrderNumber" th:field="*{thirdOrderNumber}"
                           placeholder="请输入三方订单号" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否自做</label>
                <div class="layui-input-block">
                    <div class="radio-box" radio-dict-code="is_self_make"
                         th:attr="default-value=*{isSelfMake}" name="isSelfMake">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单来源</label>
                <div class="layui-input-block">
                    <div class="radio-box" radio-dict-code="order_source"
                         th:attr="default-value=*{orderSource}" name="orderSource">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单状态</label>
                <div class="layui-input-block">
                    <div class="radio-box" radio-dict-code="order_status"
                         th:attr="default-value=*{orderStatus}" name="orderStatus">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">群聊名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="groupName" th:field="*{groupName}"
                           placeholder="请输入群聊名称" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">接单人员：</label>
                <div class="layui-input-block">
                    <input type="text" name="assignedTo" th:field="*{assignedTo}"
                           placeholder="请输入接单人员" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">详细描述：</label>
                <div class="layui-input-block">
                    <input type="text" name="orderDetails" th:field="*{orderDetails}"
                           placeholder="请输入详细描述" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单金额：</label>
                <div class="layui-input-block">
                    <input type="text" name="orderAmount" th:field="*{orderAmount}"
                           placeholder="请输入订单金额" class="layui-input"/>
                </div>
            </div>
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label">下单图片：</label>-->
<!--                <div class="layui-input-block">-->
<!--                    &lt;!&ndash; Image preview &ndash;&gt;-->
<!--                    <div id="image-preview" >-->
<!--                        <img src="" alt="Order Image" id="image-preview-img" style="width: 100px; height: auto; cursor: pointer;" onclick="viewImage(this.src)" />-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->


            <div class="layui-form-item">
                <label class="layui-form-label">交付日期：</label>
                <div class="layui-input-block">
                    <input type="text" name="orderAmount" th:field="*{finishTime}"
                           placeholder="请输入交付时间" class="layui-input"/>
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="orderDispatch-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</body>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    layui.use(['form', 'jquery', 'laydate', 'dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        let prefix = "/sys/orderDispatch/";

        laydate.render({
            elem: '#finishTime'
        });

        form.on('submit(orderDispatch-update)', function (data) {
            for (var key in data.field) {
                var type = $(data.form).find("input[name='" + key + "']").attr("type");
                if (type == "checkbox") {
                    var value = "";
                    $(data.form).find("input[name='" + key + "']:checked").each(function () {
                        value += $(this).val() + ",";
                    })
                    if (value != "") {
                        value = value.substr(0, value.length - 1);
                        data.field[key] = value;
                    }

                }
            }
            $.ajax({
                url: prefix + 'update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.layui.table.reload("orderDispatch-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    });
</script>
</html>
